package gapp.ctrl;

import gapp.itg.SubsysStateObservable;
import gapp.subsysstate.ISubsysState;
import gapp.subsysstate.State;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JOptionPane;


/**
 * A state changing control (and technically a listener)
 * Will not set any value in GUI, state propagated with observer
 * pattern
 * @author hajo
 *
 */
@SuppressWarnings("serial")
// Package private
class StateCtrl extends AbstractAction {
	
	// Set the text on button
	public StateCtrl(String string) {
		super(string);
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		System.out.println("State control");
		try {	
			ISubsysState sso = SubsysStateObservable.getInstance();
			State state = sso.getState();
			if( state == State.STATE_1 ){
				sso.setState(State.STATE_2);
			}else{
				sso.setState(State.STATE_1);
			}
		} catch (Throwable e) {
			JOptionPane.showMessageDialog(null, "Bad state");
		}
	}
}
